package com.hzzh.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hzzh.service.MeetingRoomService;
import com.hzzh.service.MeetingService;
import com.hzzh.vo.Meeting;

/**
 * Servlet implementation class ViewMyBookingServlet
 */
@WebServlet("/ViewMyBookingServlet")
public class ViewMyBookingServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewMyBookingServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//获取session对象
		HttpSession session=request.getSession();
		//取得预定者id
		int reservationistid=(Integer) session.getAttribute("employeeid");
		MeetingService service=new MeetingService();
		MeetingRoomService roomService=new MeetingRoomService();
		//根据id查询所有会议
		List<Meeting> meetingsList=service.viewMyBookingInfo(reservationistid);
		List<String>  roomsNameList=new ArrayList<String>();
		for(Meeting m:meetingsList){
			//根据会议中的roomid，查询得到会议名字，存到roomsNameList里
			roomsNameList.add(roomService.viewOneMeetingRoom(m.getRoomid()).getRoomname());
		}
		
		Map<Meeting,String> map=new HashMap<Meeting,String>();
		
		for(int i=0;i<meetingsList.size();i++){
			//把会议对象，会议室名字保存到HashMap对象中
			map.put(meetingsList.get(i), roomsNameList.get(i));
		}
		request.setAttribute("map", map);
		
		request.getRequestDispatcher("mybookings.jsp").forward(request, response);
		
		
	}

}
